package com.jzhao.jpre.service.backend.impl;

import com.jzhao.jpre.base.DataCommIOException;
import com.jzhao.jpre.base.DataCommRecvErrorException;
import com.jzhao.jpre.channel.comm.DataCommConnectException;
import com.jzhao.jpre.service.backend.DataConnectionBase;

public class TcpSyncShortData extends DataConnectionBase {
	public Object dataComm(Object msg) throws DataCommIOException,
			DataCommRecvErrorException {
		byte[] sendMsg = (byte[]) msg;
		commConnection.connect();
		try {
			commConnection.send(sendMsg);
		} catch (DataCommConnectException ce) {
			throw new DataCommIOException(ce.getMessage());
		}
		byte[] recvMsg = (byte[]) commConnection.recv();
		commConnection.release();
		return recvMsg;
	}

	public void write(Object msg) throws DataCommIOException,
			DataCommRecvErrorException {
		// TODO Auto-generated method stub
		byte[] sendMsg = (byte[]) msg;
		commConnection.connect();
		try {
			commConnection.send(sendMsg);
		} catch (DataCommConnectException ce) {
			throw new DataCommIOException(ce.getMessage());
		}
		commConnection.release();
	}
}
